package main

import (
	"fmt"
	"iot-base/devc/common/loader"
)

func ReadFuncProxy(Param loader.Param, result []byte) interface{} {
	_, ok := PropertyDecodeFun[Param.Func]
	if ok {
		result := PropertyDecodeFun[Param.Func](result, Param)
		return result
	} else {
		fmt.Println("no this func!:", Param.Func)
		return nil
	}
}

//增加云璟log函数规则
func YLog(data []byte, param loader.Param) interface{} {
	var log []string
	if len(data) < 4 {
		fmt.Println("read log err!")
		return nil
	}
	index := []int{}
	for i := 0; i < len(data); i++ {
		if data[i] == 0x23 && data[i+1] == 0x24 && data[i+2] == 0x23 && data[i+3] == 0x24 {
			index = append(index, i)
			continue
		}
	}
	for i := 0; i < len(index)-1; i++ {
		year := ByteToInt16(data[index[i]:index[i]+2], param)
		month := ByteToInt16(data[index[i]+2:index[i]+4], param)
		day := ByteToInt16(data[index[i]+4:index[i]+6], param)
		hour := ByteToInt16(data[index[i]+6:index[i]+8], param)
		minute := ByteToInt16(data[index[i]+8:index[i]+10], param)
		second := ByteToInt16(data[index[i]+10:index[i]+12], param)
		fmt.Println("year:", year, " month:", month, " day:", day, " hour:", hour, " minute:", minute, " second:", second)
		fmt.Println(string(data[index[i]+12 : index[i+1]]))
		log = append(log, fmt.Sprint(year, "-", month, "-", day, " ", hour, ":", minute, ":", second, "\nlog:"), string(data[index[i]+12:index[i+1]]))
	}
	return log
}
